//
//  MoneyViewController.m
//  FruitVIP
//
//  Created by 孙艳玲 on 15/7/14.
//  Copyright (c) 2015年 孙艳玲. All rights reserved.
//

#import "MoneyViewController.h"

#define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)
#define SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height)

@interface MoneyViewController ()

@end

@implementation MoneyViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.isSelected = NO;

    self.view.backgroundColor = [UIColor whiteColor];
    
         //优惠券已使用页面
        self.usedTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 50, SCREEN_WIDTH, SCREEN_HEIGHT - 64 - 49 -50)];
    //    self.usedTableView.backgroundColor = [UIColor colorWithRed:163/255.0 green:148/255.0 blue:132/ 255.0 alpha:1];
        self.usedTableView.backgroundColor = [UIColor whiteColor];
        //优惠券未使用页面的代理
        self.usedTableView.delegate = self;
        self.usedTableView.dataSource = self;
        //设置优惠券未使用页面的tag值
        self.usedTableView.tag = 1002;
        //取消分割线
        self.usedTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        [self.view addSubview:self.usedTableView];
    
    
        //优惠券已过期页面
        self.pastDueTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 50, SCREEN_WIDTH, SCREEN_HEIGHT - 64 - 49 - 50)];
    //    self.pastDueTableView.backgroundColor = [UIColor colorWithRed:163/255.0 green:148/255.0 blue:132/ 255.0 alpha:1];
        self.pastDueTableView.backgroundColor = [UIColor whiteColor];
        //优惠券未使用页面的代理
        self.pastDueTableView.delegate = self;
        self.pastDueTableView.dataSource = self;
        //设置优惠券未使用页面的tag值
        self.pastDueTableView.tag = 1003;
        //取消分割线
        self.pastDueTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        [self.view addSubview:self.pastDueTableView];
    
    
    
        //优惠券未使用页面
        self.unUsedTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 50, SCREEN_WIDTH, SCREEN_HEIGHT - 64 - 49 - 50)];
        //    self.unUsedTableView.backgroundColor = [UIColor colorWithRed:163/255.0 green:148/255.0 blue:132/ 255.0 alpha:1];
        self.unUsedTableView.backgroundColor = [UIColor whiteColor];
        //优惠券未使用页面的代理
        self.unUsedTableView.delegate = self;
        self.unUsedTableView.dataSource = self;
        //设置优惠券未使用页面的tag值
        self.unUsedTableView.tag = 1001;
        //取消分割线
    //    self.unUsedTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        [self.view addSubview:self.unUsedTableView];
    
    
    
    
        self.unUsedButton = [UIButton buttonWithType:UIButtonTypeCustom];
        self.unUsedButton.frame = CGRectMake(10, 10, SCREEN_WIDTH/5, 30  );
        self.unUsedButton.backgroundColor = [UIColor colorWithRed:109.0/255.0 green:77.0 / 255.0 blue:69 / 255.0 alpha:1];
        [self.unUsedButton setTitle:@"可使用" forState:UIControlStateNormal];
        self.unUsedButton.titleLabel.font = [UIFont systemFontOfSize:13];
        [self.unUsedButton setTitleColor:[UIColor colorWithRed:242.0 / 255.0 green:204.0 / 255.0 blue:49.0 / 255.0 alpha:1] forState:UIControlStateNormal];
        [self.unUsedButton addTarget:self action:@selector(unUsedButtonAction) forControlEvents:UIControlEventTouchUpInside];
    self.unUsedButton.layer.cornerRadius = CGRectGetHeight([self.unUsedButton bounds])/5;
        [self.view addSubview:self.unUsedButton];
    
        self.usedButton = [UIButton buttonWithType:UIButtonTypeCustom];
        self.usedButton.frame = CGRectMake(self.unUsedButton.frame.origin.x + self.unUsedButton.frame.size.width + 50 , 10, self.unUsedButton.frame.size.width, 30 );
    self.usedButton.backgroundColor = [UIColor colorWithRed:240/255.0 green:240/255.0 blue:240/255.0 alpha:1];
    [self.usedButton setTitle:@"已使用" forState:UIControlStateNormal];
        self.usedButton.titleLabel.font = [UIFont systemFontOfSize:13];
        [self.usedButton setTitleColor:[UIColor colorWithRed:71.0 / 255.0 green:61.0 / 255.0 blue:55.0 / 255.0 alpha:1] forState:UIControlStateNormal];
        [self.usedButton addTarget:self action:@selector(usedButtonAction) forControlEvents:UIControlEventTouchUpInside];
    self.usedButton.layer.cornerRadius = CGRectGetHeight([self.usedButton bounds])/5;
        [self.view addSubview:self.usedButton];
    
        self.pastDueButton = [UIButton buttonWithType:UIButtonTypeCustom];
        self.pastDueButton.frame = CGRectMake(self.usedButton.frame.origin.x + self.usedButton.frame.size.width + 50, 10,self.usedButton.frame.size.width , 30);
        self.pastDueButton.backgroundColor = [UIColor colorWithRed:240/255.0 green:240/255.0 blue:240/255.0 alpha:1];
        [self.pastDueButton setTitle:@"已过期" forState:UIControlStateNormal];
        self.pastDueButton.titleLabel.font = [UIFont systemFontOfSize:13];
        [self.pastDueButton setTitleColor:[UIColor colorWithRed:71.0 / 255.0 green:61.0 / 255.0 blue:55.0 / 255.0 alpha:1] forState:UIControlStateNormal];
        [self.pastDueButton addTarget:self action:@selector(pastDueButtonAction) forControlEvents:UIControlEventTouchUpInside];
    self.pastDueButton.layer.cornerRadius = CGRectGetHeight([self.pastDueButton bounds])/5;
        [self.view addSubview:self.pastDueButton];
    

}

- (void)unUsedButtonAction
{
    self.unUsedButton.backgroundColor = [UIColor colorWithRed:109.0/255.0 green:77.0 / 255.0 blue:69 / 255.0 alpha:1];
    [self.unUsedButton setTitleColor:[UIColor colorWithRed:242.0 / 255.0 green:204.0 / 255.0 blue:49.0 / 255.0 alpha:1] forState:UIControlStateNormal];
    self.usedButton.backgroundColor = [UIColor colorWithRed:240/255.0 green:240/255.0 blue:240/255.0 alpha:1];
    [self.usedButton setTitleColor:[UIColor colorWithRed:71.0 / 255.0 green:61.0 / 255.0 blue:55.0 / 255.0 alpha:1] forState:UIControlStateNormal];
    self.pastDueButton.backgroundColor = [UIColor colorWithRed:240/255.0 green:240/255.0 blue:240/255.0 alpha:1];
    [self.pastDueButton setTitleColor:[UIColor colorWithRed:71.0 / 255.0 green:61.0 / 255.0 blue:55.0 / 255.0 alpha:1] forState:UIControlStateNormal];
    [self.view addSubview:self.unUsedTableView];
}
- (void)usedButtonAction
{
    self.usedButton.backgroundColor = [UIColor colorWithRed:109.0/255.0 green:77.0 / 255.0 blue:69 / 255.0 alpha:1];
    [self.usedButton setTitleColor:[UIColor colorWithRed:242.0 / 255.0 green:204.0 / 255.0 blue:49.0 / 255.0 alpha:1] forState:UIControlStateNormal];
    self.unUsedButton.backgroundColor = [UIColor colorWithRed:240/255.0 green:240/255.0 blue:240/255.0 alpha:1];
    [self.unUsedButton setTitleColor:[UIColor colorWithRed:71.0 / 255.0 green:61.0 / 255.0 blue:55.0 / 255.0 alpha:1] forState:UIControlStateNormal];
    self.pastDueButton.backgroundColor = [UIColor colorWithRed:240/255.0 green:240/255.0 blue:240/255.0 alpha:1];
    [self.pastDueButton setTitleColor:[UIColor colorWithRed:71.0 / 255.0 green:61.0 / 255.0 blue:55.0 / 255.0 alpha:1] forState:UIControlStateNormal];
    [self.view addSubview:self.usedTableView];
}
- (void)pastDueButtonAction
{
    self.pastDueButton.backgroundColor = [UIColor colorWithRed:109.0/255.0 green:77.0 / 255.0 blue:69 / 255.0 alpha:1];
    [self.pastDueButton setTitleColor:[UIColor colorWithRed:242.0 / 255.0 green:204.0 / 255.0 blue:49.0 / 255.0 alpha:1] forState:UIControlStateNormal];
    self.unUsedButton.backgroundColor = [UIColor colorWithRed:240/255.0 green:240/255.0 blue:240/255.0 alpha:1];
    [self.unUsedButton setTitleColor:[UIColor colorWithRed:71.0 / 255.0 green:61.0 / 255.0 blue:55.0 / 255.0 alpha:1] forState:UIControlStateNormal];
    self.usedButton.backgroundColor = [UIColor colorWithRed:240/255.0 green:240/255.0 blue:240/255.0 alpha:1];
    [self.usedButton setTitleColor:[UIColor colorWithRed:71.0 / 255.0 green:61.0 / 255.0 blue:55.0 / 255.0 alpha:1] forState:UIControlStateNormal];

    [self.view addSubview:self.pastDueTableView];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (1001 == tableView.tag) {
        return 5;
    }
    if (1002 == tableView.tag) {
        return 4;
    }
    else
        return 5;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:nil];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
    }

    if (tableView.tag == 1001) {

        UIImageView *unUsedImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, SCREEN_WIDTH - 20, 90)];
        unUsedImageView.userInteractionEnabled = YES;
        UIImage *unUsedImage = [UIImage imageNamed:@"canUse.png"];
//        unUsedImageView.contentMode = UIViewContentModeScaleAspectFit;
        unUsedImageView.image = unUsedImage;
        [cell addSubview:unUsedImageView];
        
        UILabel *moneyLabel = [[UILabel alloc] initWithFrame:CGRectMake(unUsedImageView.frame.size.width/15, unUsedImageView.frame.size.height/4, unUsedImageView.frame.size.width/6, unUsedImageView.frame.size.height/3)];
        moneyLabel.text = @"99";
        moneyLabel.textColor = [UIColor colorWithRed:223/255.0 green:15/255.0 blue:49/255.0 alpha:1];
        moneyLabel.font = [UIFont systemFontOfSize:25];
        moneyLabel.textAlignment = NSTextAlignmentRight;
//        moneyLabel.backgroundColor = [UIColor redColor];
        [unUsedImageView addSubview:moneyLabel];
        
        
        UILabel *sysmbelLabel = [[UILabel alloc] initWithFrame:CGRectMake(moneyLabel.frame.origin.x + moneyLabel.frame.size.width, moneyLabel.frame.origin.y + moneyLabel.frame.size.height/2, moneyLabel.frame.size.width/2, moneyLabel.frame.size.height/2)];
        sysmbelLabel.text = @"元";
        sysmbelLabel.font = [UIFont systemFontOfSize:13];
        sysmbelLabel.textAlignment = NSTextAlignmentLeft;
        sysmbelLabel.textColor = [UIColor colorWithRed:223/255.0 green:15/255.0 blue:49/255.0 alpha:1];
//        sysmbelLabel.backgroundColor = [UIColor yellowColor];
        [unUsedImageView addSubview:sysmbelLabel];
        

        UILabel *dataLabel = [[UILabel alloc] initWithFrame:CGRectMake(sysmbelLabel.frame.origin.x + sysmbelLabel.frame.size.width + 5, unUsedImageView.frame.size.height - 30, unUsedImageView.frame.size.width/2, 20)];
        dataLabel.text = @"2015-07-01至2015-08-08";
        dataLabel.textColor = [UIColor colorWithRed:151/255.0 green:134.0/255.0 blue:129/255.0 alpha:1];
        dataLabel.font = [UIFont systemFontOfSize:10];
        dataLabel.textAlignment = NSTextAlignmentLeft;
        [unUsedImageView addSubview:dataLabel];
        
    }
    if (tableView.tag == 1002) {
        UIImageView *unUsedImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, SCREEN_WIDTH - 20, 90)];
        unUsedImageView.userInteractionEnabled = YES;
        UIImage *unUsedImage = [UIImage imageNamed:@"cannotUse.png"];
//        unUsedImageView.contentMode = UIViewContentModeScaleAspectFit;
        unUsedImageView.image = unUsedImage;
        [cell addSubview:unUsedImageView];
        
        UILabel *moneyLabel = [[UILabel alloc] initWithFrame:CGRectMake(unUsedImageView.frame.size.width/15, unUsedImageView.frame.size.height/4, unUsedImageView.frame.size.width/6, unUsedImageView.frame.size.height/3)];
        moneyLabel.text = @"99";
        moneyLabel.textColor = [UIColor colorWithRed:200/255.0 green:200/255.0 blue:200/255.0 alpha:1];
        moneyLabel.font = [UIFont systemFontOfSize:25];
        moneyLabel.textAlignment = NSTextAlignmentRight;
        [unUsedImageView addSubview:moneyLabel];
        
        
        UILabel *sysmbelLabel = [[UILabel alloc] initWithFrame:CGRectMake(moneyLabel.frame.origin.x + moneyLabel.frame.size.width, moneyLabel.frame.origin.y + moneyLabel.frame.size.height/2, moneyLabel.frame.size.width/2, moneyLabel.frame.size.height/2)];
        sysmbelLabel.text = @"元";
        sysmbelLabel.font = [UIFont systemFontOfSize:13];
        sysmbelLabel.textAlignment = NSTextAlignmentLeft;
        sysmbelLabel.textColor = [UIColor colorWithRed:200/255.0 green:200/255.0 blue:200/255.0 alpha:1];
        //        sysmbelLabel.backgroundColor = [UIColor yellowColor];
        [unUsedImageView addSubview:sysmbelLabel];
        
        
        UILabel *dataLabel = [[UILabel alloc] initWithFrame:CGRectMake(sysmbelLabel.frame.origin.x + sysmbelLabel.frame.size.width + 5, unUsedImageView.frame.size.height - 30, unUsedImageView.frame.size.width/2, 20)];
        dataLabel.text = @"2015-07-01至2015-08-08";
        dataLabel.textColor = [UIColor colorWithRed:200/255.0 green:200/255.0 blue:200/255.0 alpha:1];
        dataLabel.font = [UIFont systemFontOfSize:10];
        dataLabel.textAlignment = NSTextAlignmentLeft;
        [unUsedImageView addSubview:dataLabel];
        
        
        UIImageView *canUsedImageView = [[UIImageView alloc] initWithFrame:CGRectMake(dataLabel.frame.origin.x + dataLabel.frame.size.width - 50, 10, dataLabel.frame.size.width/2, unUsedImageView.frame.size.height - 20)];
        canUsedImageView.contentMode = UIViewContentModeScaleAspectFit;
        UIImage *canUsedImage = [UIImage imageNamed:@"useOut.png"];
//        canUsedImageView.backgroundColor = [UIColor redColor];
        canUsedImageView.image = canUsedImage;
        [unUsedImageView addSubview:canUsedImageView];
    }
    if (tableView.tag == 1003) {
        UIImageView *unUsedImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, SCREEN_WIDTH - 20, 90)];
        unUsedImageView.userInteractionEnabled = YES;
        UIImage *unUsedImage = [UIImage imageNamed:@"cannotUse.png"];
//        unUsedImageView.contentMode = UIViewContentModeScaleAspectFit;
        unUsedImageView.image = unUsedImage;
        [cell addSubview:unUsedImageView];
        
        UILabel *moneyLabel = [[UILabel alloc] initWithFrame:CGRectMake(unUsedImageView.frame.size.width/15, unUsedImageView.frame.size.height/4, unUsedImageView.frame.size.width/6, unUsedImageView.frame.size.height/3)];
        moneyLabel.text = @"99";
        moneyLabel.textColor = [UIColor colorWithRed:200/255.0 green:200/255.0 blue:200/255.0 alpha:1];
        moneyLabel.font = [UIFont systemFontOfSize:25];
        moneyLabel.textAlignment = NSTextAlignmentRight;
        [unUsedImageView addSubview:moneyLabel];
        
        
        UILabel *sysmbelLabel = [[UILabel alloc] initWithFrame:CGRectMake(moneyLabel.frame.origin.x + moneyLabel.frame.size.width, moneyLabel.frame.origin.y + moneyLabel.frame.size.height/2, moneyLabel.frame.size.width/2, moneyLabel.frame.size.height/2)];
        sysmbelLabel.text = @"元";
        sysmbelLabel.font = [UIFont systemFontOfSize:13];
        sysmbelLabel.textAlignment = NSTextAlignmentLeft;
        sysmbelLabel.textColor = [UIColor colorWithRed:200/255.0 green:200/255.0 blue:200/255.0 alpha:1];
        //        sysmbelLabel.backgroundColor = [UIColor yellowColor];
        [unUsedImageView addSubview:sysmbelLabel];
        
        
        UILabel *dataLabel = [[UILabel alloc] initWithFrame:CGRectMake(sysmbelLabel.frame.origin.x + sysmbelLabel.frame.size.width + 5, unUsedImageView.frame.size.height - 30, unUsedImageView.frame.size.width/2, 20)];
        dataLabel.text = @"2015-07-01至2015-08-08";
        dataLabel.textColor = [UIColor colorWithRed:200/255.0 green:200/255.0 blue:200/255.0 alpha:1];
        dataLabel.font = [UIFont systemFontOfSize:10];
        dataLabel.textAlignment = NSTextAlignmentLeft;
        [unUsedImageView addSubview:dataLabel];
        
        UIImageView *canUsedImageView = [[UIImageView alloc] initWithFrame:CGRectMake(dataLabel.frame.origin.x + dataLabel.frame.size.width - 50, 10, dataLabel.frame.size.width/2, unUsedImageView.frame.size.height - 20)];
        canUsedImageView.contentMode = UIViewContentModeScaleAspectFit;
        UIImage *canUsedImage = [UIImage imageNamed:@"outTime.png"];
        //        canUsedImageView.backgroundColor = [UIColor redColor];
        canUsedImageView.image = canUsedImage;
        [unUsedImageView addSubview:canUsedImageView];

    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 110;
}

- (void)buttonAction:(UIButton *)button
{
    NSLog(@"勾选");

    if (self.isSelected == NO) {
        self.isSelected = YES;
        [button setImage:[UIImage imageNamed:@"danxuan.png"] forState:UIControlStateNormal];
           }
    else{
        self.isSelected = NO;
        [button setImage:[UIImage imageNamed:nil] forState:UIControlStateNormal];
    }

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
